package top.zxybird.demo.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by zxybird on 2018/2/22.
 */
public class FutureDemo {

  private static class Chuju {
  }

  private static class Shicai {
  }

  private static class OnlineShopping implements Callable<Chuju> {
    @Override
    public Chuju call() throws Exception {
      Thread.sleep(5 * 1000);
      return new Chuju();
    }
  }

  private static class Shopping implements Callable<Shicai> {

    @Override
    public Shicai call() throws Exception {
      Thread.sleep(12 * 1000);
      return new Shicai();
    }
  }

  public static void main(String[] args) throws ExecutionException, InterruptedException {

    long begin = System.currentTimeMillis();

    FutureTask<Chuju> chujuFutureTask = new FutureTask<>(new OnlineShopping());
    new Thread(chujuFutureTask).start();

    FutureTask<Shicai> shicaiFutureTask = new FutureTask<>(new Shopping());
    new Thread(shicaiFutureTask).start();

    chujuFutureTask.get();
    shicaiFutureTask.get();

    System.out.println(System.currentTimeMillis() - begin);

  }

}
